<?php

define('TEST_HOST', 'ami.musdb.net');
define('DEBUG', $_SERVER['HTTP_HOST'] == TEST_HOST);

//$debug = false;

define('INDEX', true);
define('USE_STATS', true);

define('RECORDS_PER_PAGE', 50);

define('MAX_ARTIST_CHARS', 26);
define('MAX_RELEASE_CHARS', 26);
define('MAX_TAG_CHARS', 18);

define('MUSDB_MAX_IMAGE_SIZE', 500 * 1024); // 500KB
define('MAX_ARTIST_NAME_LENGTH', 128);
define('MAX_ARTIST_URL_LENGTH', 128);
define('MAX_ARTIST_COUNTRY_LENGTH', 64);

define('MAX_LABEL_NAME_LENGTH', 128);
define('MAX_MEMBER_NAME_LENGTH', 128);
define('MAX_TAG_NAME_LENGTH', 64);
define('MAX_RELEASE_NAME_LENGTH', 128);
define('MAX_RELEASE_SCHEDULE_DATE_LENGTH', 32);

define('MAX_USER_NAME_LENGTH', 32);
define('MIN_USER_NAME_LENGTH', 3);
define('MAX_USER_PW_LENGTH', 32);
define('MIN_USER_PW_LENGTH', 5);
define('MAX_USER_EMAIL_LENGTH', 128);
define('MAX_USER_BAN_REASON_LENGTH', 128);

define('ARTISTS_THUMB_DIR', 'data/artists/');
define('ARTISTS_THUMB_WIDTH', 200);
define('ARTISTS_THUMB_HEIGHT', 200);
define('RELEASES_THUMB_DIR', 'data/releases/');
define('RELEASES_THUMB_WIDTH', 200);
define('RELEASES_THUMB_HEIGHT', 200);
define('USERPICS_THUMB_DIR', 'data/userpics/');
define('USERPICS_THUMB_WIDTH', 70);
define('USERPICS_THUMB_HEIGHT', 120);

define('MAX_COMMENT_LENGTH', 1024);

define('SESSION_NAME', 'MUSDB');
define('ANONYMOUS_USER_NAME', 'Anonymous');

$VALID_IMG_TYPES = array(IMAGETYPE_JPEG, IMAGETYPE_PNG);
$VALID_IMG_TYPES_STR = 'JPEG, PNG';

define('PASSWORD_KEY', 'TOSAKALOVESARCHER');

define('NG', 'v2/');

include './inc/misc.inc.php';

require_once NG.'init/exceptions.init.php';

// Load stuff
require_once NG.'init/misc.init.php';

require_once 'PEAR.php';
require_once 'DB.php';

require_once NG.'classes/image.class.php';

require_once NG.'classes/iDBO.php';
require_once NG.'classes/iSingletone.php';

require_once NG.'classes/Singletone.php';
require_once NG.'classes/Picture.php';
require_once NG.'classes/DBObject.php';

require_once NG.'classes/DBField.php';
require_once NG.'classes/DBBoolean.php';
require_once NG.'classes/Artist.php';

require_once NG.'classes/DBO.php';

require_once NG.'classes/DBString.php';
require_once NG.'classes/DBDate.php';
require_once NG.'classes/DBUrl.php';
require_once NG.'classes/DBComment.php';
require_once NG.'classes/DBInteger.php';
require_once NG.'classes/DBYear.php';
require_once NG.'classes/DBRecordTypeId.php';
require_once NG.'classes/DBLength.php';
require_once NG.'classes/DBTrackCount.php';
require_once NG.'classes/Label.php';
require_once NG.'classes/Member.php';
require_once NG.'classes/Release.php';
require_once NG.'classes/Tag.php';

require_once NG.'classes/Stats.php';
require_once NG.'classes/ReleaseList.php';
require_once NG.'classes/LabelList.php';
require_once NG.'classes/RecordTypeList.php';

require_once NG.'classes/User.php';
require_once NG.'classes/Auth.php';
require_once NG.'classes/Search.php';
require_once NG.'classes/Todo.php';
require_once NG.'classes/Lastfm.php';

$lfm = new Lastfm;

$dbo = DBO::getInstance();

$artists = $dbo->getAll('SELECT id, trim(name) as name FROM mtl.artists WHERE picture_path LIKE \'http%\'', null, DB_FETCHMODE_ASSOC);

$skip = 0;
$i = 0;
foreach($artists as $arr) {
    $i++;
    if($i < $skip)
        continue;

    echo $arr['name'].": ";

    try {
        
        $pic = $lfm->updateArtistPicture($arr['id']);

    } catch (Exception $e) {

        $pic = null;
    }

    echo $pic ."\n";
    sleep(5);
}